<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		//var isUseCommon = document.getElementById("isUseCommon");
	
		var agingSettings = document.getElementsByName("agingSettings");
		var agingDay = document.getElementById("agingDay");
		
		var hisAgingSettings = document.getElementById("hisAgingSettings");
		var hisDay = document.getElementById("hisDay");
		
		var updateStatus = document.getElementsByName("updateStatus");
		var customerInfoStatus = document.getElementById("customerInfoStatus");
		var saleStageStatus = document.getElementById("saleStageStatus");
		var saleRecordStatus = document.getElementById("saleRecordStatus");
		
		var usefulTimes = document.getElementsByName("usefulTime");
		
		if(agingSettings[0].checked && agingDay.value == ""){
			alert("<fmt:message key='open.message.unifyDay'/>");
			return false;
		}
		
		if(agingSettings[1].checked){
			for(var i = 0; i < usefulTimes.length; i++){
				if(usefulTimes[i].value == ""){
					alert("<fmt:message key='open.lable.usefulTime'/><fmt:message key='common.message.empty'/>");
					return false;
				}
			}
		}
		
		if(hisAgingSettings.checked && hisDay.value == ""){
			alert("<fmt:message key='open.message.hisDay'/>");
			return false;
		}
		
		if(updateStatus[1].checked){
			if(!customerInfoStatus.checked && 
				!saleStageStatus.checked && 
				!saleRecordStatus.checked){
				alert("<fmt:message key='open.message.typeRecord'/>");
				return false;
			}
		}
		return true;
	}
	
	//当公海规则启用后，当前表单中的所有元素都变为可用状态
	function setNodes(id){
		var obj = document.getElementById(id);
		var nodes = document.commontSetForm.elements;
		for(var i = 0; i < nodes.length; i++){
			var node = document.commontSetForm.elements[i];
			if(obj.checked && id != node.name){
				node.disabled = false;
			}else{
				if(id != node.name){
					node.disabled = true;
				}
			}
		}
	}
	
	function switchSysBar(rObj,id,name){
		var obj = document.getElementById(id);
		var rObjs = document.getElementsByName(name);
		if(obj.style.display == "none" && rObj.checked && rObj == rObjs[1]){
			document.getElementById(id).style.display = "block";
		}else if(rObj.checked && rObj != rObjs[1]){
			document.getElementById(id).style.display = "none";
		}
	}
	
	function save(){
		if(checkForm()){
			document.commontSetForm.action = "./commonSettings.do?action=updateCommonSettings";
			document.commontSetForm.target = "main";
			document.commontSetForm.submit();
		}
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='common.message.addSuccess'/>");
		}else if("<c:out value='${result}'/>" == 2){
			//alert("已关闭公海规则，将当前公海客户转入到异动客户中吗？");
			if(confirm("已关闭公海规则，将当前公海客户转入到异动客户中吗？")){
				document.commontSetForm.action = "./commonSettings.do?action=moveToExceptionCustomer";
				document.commontSetForm.target = "main";
				document.commontSetForm.submit();
			}
		}else if("<c:out value='${result}'/>" == 3){
			alert("转移成功！");
		}
		
		setNodes("isUseCommon");
		
		if("<c:out value='${commonSettings.agingSettings}'/>" == 1){
			document.getElementById("frmSaleStage").style.display = "block";
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="commontSetForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='open.title.main'/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:save();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table_style" height="30" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title2">
							<input id="isUseCommon" name="isUseCommon" type="checkbox" <c:if test='${commonSettings.isUseCommon != 0}'>checked</c:if> 
								value="1" onclick="setNodes('isUseCommon')"/><fmt:message key='open.lable.common'/>
						</td>
						<!-- 
						<td class="title3">
							<input id="isUseDeptCommon" name="isUseDeptCommon" type="checkbox" <c:if test='${commonSettings.isUseCommon == 2}'>checked</c:if> 
								value="2"/><fmt:message key='open.lable.deptCommon'/>
						</td>
						 -->
					</tr>
				</table>
				
				<table class="table_style">
					<tr>
						<td class="title" colspan="2"><fmt:message key='open.lable.customerSet'/></td>
					</tr>
					<tr>
						<td class="title4" width="8%"><fmt:message key='common.lable.checkbox'/></td>
						<td class="title4"><fmt:message key='open.lable.setType'/></td>
					</tr>
					<tr>
						<td align="center">
							<input id="dueCustomer" name="dueCustomer" type="radio" <c:if test='${commonSettings.dueCustomer == 0}'>checked</c:if> 
								value="0"/>
						</td>
						<td><fmt:message key='open.lable.commonCustomer'/></td>
					</tr>
					<tr>
						<td align="center">
							<input id="dueCustomer" name="dueCustomer" type="radio" <c:if test='${commonSettings.dueCustomer == 1}'>checked</c:if> 
								value="1"/>
						</td>
						<td><fmt:message key='open.lable.exceptionCustomer'/></td>
					</tr>
				</table><br><br>
				
				<table class="table_style">
					<tr>
						<td class="title" colspan="3"><fmt:message key='open.lable.agingSet'/></td>
					</tr>
					<tr>
						<td class="title4" width="8%"><fmt:message key='common.lable.checkbox'/></td>
						<td class="title4"><fmt:message key='open.lable.setType'/></td>
					</tr>
					<tr>
						<td align="center">
							<input id="agingSettings" name="agingSettings" type="radio" <c:if test='${commonSettings.agingSettings == 0}'>checked</c:if> 
								value="0" onclick="switchSysBar(this,'frmSaleStage','agingSettings')"/>
						</td>
						<td>
							<fmt:message key='open.lable.unify1'/>
							<input id="agingDay" name="agingDay" type="text" size="5" value="${commonSettings.agingDay}" onkeyup="onlyNumber(this)"/>
							<fmt:message key='open.lable.unify2'/>
						</td>
					</tr>
					<tr>
						<td align="center"><input id="agingSettings" name="agingSettings" type="radio" <c:if test='${commonSettings.agingSettings == 1}'>checked</c:if> 
							value="1" onclick="switchSysBar(this,'frmSaleStage','agingSettings')"/></td>
						<td><fmt:message key='open.lable.saleStage'/></td>
					</tr>
					<tr style="display: none;">
						<td></td>
						<td></td>
					</tr>
					<tr id="frmSaleStage" style="display: none;">
						<td class="title3"></td>
						<td class="title3" width="300">
							<table class="table_style" style="text-align: center;">
								<tr>
									<td class="title4"><fmt:message key='open.lable.stage'/></td>
									<td class="title4" width="80"><fmt:message key='open.lable.usefulTime'/>(<fmt:message key='common.lable.day'/>)</td>
								</tr>
								<c:forEach var="saleStage" items="${commonSettings.saleStages}">
								<tr>
									<td>
										${saleStage.stageName}
										<input id="saleStageId" name="saleStageId" type="hidden" value="${saleStage.id}"/>
									</td>
									<td>
										<input id="usefulTime" name="usefulTime" class="input2" type="text" 
											value="${saleStage.usefulTime}" onkeyup="onlyNumber(this)"/>
									</td>
								</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
					<tr>
						<td align="center">
							<input id="hisAgingSettings" name="hisAgingSettings" type="checkbox" 
								<c:if test='${commonSettings.hisAgingSettings == 1}'>checked</c:if> value="1"/>
						</td>
						<td>
							<fmt:message key='open.lable.history1'/>
							<input id="hisDay" name="hisDay" type="text" size="5" value="${commonSettings.hisDay}" onkeyup="onlyNumber(this)"/>
							<fmt:message key='open.lable.history2'/>
						</td>
					</tr>
				</table><br><br>
				
				<table class="table_style">
					<tr>
						<td class="title" colspan="3"><fmt:message key='open.lable.updateStatus'/></td>
					</tr>
					<tr>
						<td class="title4" width="8%"><fmt:message key='common.lable.checkbox'/></td>
						<td class="title4"><fmt:message key='open.lable.method'/></td>
					</tr>
					<tr>
						<td align="center">
							<input id="updateStatus" name="updateStatus" type="radio" <c:if test='${commonSettings.updateStatus == 0}'>checked</c:if> 
								value="0"/>
						</td>
						<td><fmt:message key='open.lable.anywhere'/></td>
					</tr>
					<tr>
						<td align="center">
							<input id="updateStatus" name="updateStatus" type="radio" <c:if test='${commonSettings.updateStatus == 1}'>checked</c:if> 
								value="1"/>
						</td>
						<td>
							<fmt:message key='open.lable.selectMethod'/>&nbsp;&nbsp;
							<input id="customerInfoStatus" name="customerInfoStatus" type="checkbox" <c:if test='${commonSettings.customerInfoStatus == 1}'>checked</c:if> 
								value="1"/><fmt:message key='open.lable.customerInfo'/>&nbsp;&nbsp;&nbsp;&nbsp;
							<input id="saleStageStatus" name="saleStageStatus" type="checkbox" <c:if test='${commonSettings.saleStageStatus == 1}'>checked</c:if> 
								value="1"/><fmt:message key='open.lable.saleStageInfo'/>&nbsp;&nbsp;&nbsp;&nbsp;
							<input id="saleRecordStatus" name="saleRecordStatus" type="checkbox" <c:if test='${commonSettings.saleRecordStatus == 1}'>checked</c:if> 
								value="1"/><fmt:message key='open.lable.saleRecordInfo'/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>